<?php
namespace app\app\controller;

use alisms\Alidayu;
use app\common\controller\App;
use Common\utils\Alisms;
use extend\alisms\AlismsApi;
use think\captcha\Captcha;
use think\Config;
use think\console\command\optimize\Schema;
use think\console\command\Version;
use think\Db;
use think\Exception;
use think\route\Rule;

/**
 * 公共方法，发送短信、省市区三级联动等
 */
class Index extends App
{


    //首页内容
    public function index()
    {
         $member=model("Member")->getAppLoginInfo();
         $house_id=empty($member)?0:$member['house_id'];
        $ads=model("Ads")->where(['house_id'=>$house_id])
            ->order("id desc")
            ->page(1,5)
            ->select()->each(function ($item){
               $item['image_path']=model("File")->getPath($item['image_id']);
            });
        $gonggao=Db::name("Gonggao")->where(['house_id'=>$house_id])->order("id desc")->value('title');
        $data=[
            'gonggao'=>$gonggao,
            'ads'=>$ads
        ];
        return $this->ok('请求成功',$data);

    }

    //房子详情
    public function house_detail()
    {
        $id=request()->param("id",'0','intval');
        $page=request()->param("page",'1','intval');
        $detail=model("House")->where(['id'=>$id])->find();
        $uid=$this->getLoginUid();

        if (empty($detail)){
            return $this->fail('房子不存在');
        }

        $detail['images']=model("Common/File")->getPaths($detail['images']);
        $type=model('House')::TYPE;


        $house_type=isset($type[$detail['type']])?$type[$detail['type']]:'';

        $address=model("Area")->area_data($detail['city_id'],$detail['area_id'],$detail['address']);
        $detail['spec_title']=$detail['area_big'].'㎡|'.$house_type.'|'.$address;


        $detail['tab']=Db::name("Sign")->where('id','in',$detail['tab'])->column('title');

        $house_config=model('HouseConfig')
            ->where('id','in',$detail['house_config'])
            ->order("id desc")->select()->each(function ($item){
                $item['image_path']=model("File")->getPath($item['image_id']);
            });
        $detail['house_config']=$house_config;

        $has_collect=model("Collect")->where(['uid'=>$uid,'house'=>$id])->find();
        $detail['is_collect']=$has_collect;



        $comment=model("Comment")
                ->alias('a')
                ->leftJoin("Member b","a.uid=b.uid")
                ->where(['a.house_id'=>$id])
                ->page($page,8)
                ->select();


        $fangdong=Db::name("Fangdong")->where(['id'=>$detail['fangdong_id']])->find();
        if (!empty($fangdong)){
            $fangdong['head_img']=model("File")->getPath($fangdong['head_img']);
        }

        $fangdong['mobile']=isset($fangdong['mobile']) && !empty($fangdong['mobile'])?$fangdong['mobile']:'13110955660';

        $detail['comment']=$comment;
        $detail['fangdong']=$fangdong;
        $detail['notice']=empty($detail['notice'])?'':$detail['notice'];
        return $this->ok('请求成功',$detail);

    }





}
